# @author Cweili
# @version 13-9-15 下午13:18

updateList = null

apply = (id) ->
	$.post 'index/apply', 'id=' + id, (data) ->
		msg = if data.type = 'success'
			'此IP地址目前无人使用，您可以开始使用了'
		else
			'此IP地址目前已被占用，请联系'
		$('#applyModal').find('#modal-body').html(render('applyAlertTpl', data))
		$('#applyModal').modal('show')
		updateList()

$ ->

	updateList = ->
		list 'ip/list', '', '#list', (item) ->
			item.customerName = if item.customer? then item.customer.name else render('applyBtnTpl', item)
			item.ipGroupName = item.ipGroup.name
			item.commentStr = if item.comment? && item.comment != '' then item.comment else item.ipGroup.comment
			item.startTimeStr = if item.startTime then item.starTime.format() else ''
			render('listTpl', item)

	$('#editorModal').find('form').submit (e) ->
		e.preventDefault()
		save 'ip/adminSave', (data) ->
			saveAction(data, updateList)

	updateList()

	$('#loginModal').modal('show')
	$('#regBtn').click ->
		$('#loginModal').modal('hide')
		$('#regModal').modal('show')
	$('#loginBtn').click ->
		$('#regModal').modal('hide')
		$('#loginModal').modal('show')

	radio 'ipgroup/list', '', 'ipGroup', (item) ->
		render('ipGroupBtnTpl', item)
